import Taro from "@tarojs/taro";
import { BasePagesUrls, PagesNavigation } from "@/data/pages/pagesTypes";
import {
  DiscoverTabs,
  DISCOVER_TABS,
  tabLookup,
} from "@/pages/discover/discoverData";

export const navigateTo = (url: PagesNavigation) => {
  Taro.navigateTo({
    url: `/${url}`,
  });
};

export const switchTab = (url: BasePagesUrls) => {
  Taro.switchTab({
    url: `/${url}`,
  });
};

export const getDiscoverTabId = (tabName: DiscoverTabs) => {
  const [_, selectedTabData] = Object.entries(tabLookup).filter(
    ([lookupKey, _]) => lookupKey === tabName
  )[0];
  return DISCOVER_TABS.indexOf(selectedTabData.zh);
};

export const navigateToMiniProgram = (appid: string, buttonLink:string) => {
  Taro.navigateToMiniProgram({
    appId: appid,
    path: buttonLink,
    extraData: {
      foo: "bar",
    },
    // envVersion: "develop",
    success: function (res) {
      // 打开成功
    },
  });
};
